part of '../repository.dart';

const _kSubscriptionMonthDurationValue = 'month';
const _kSubscriptionYearDurationValue = 'year';

class _SubscriptionDurationDto extends Equatable {
  const _SubscriptionDurationDto._internal({
    required this.durationString,
  });

  final String durationString;

  @override
  List<Object?> get props {
    return [
      durationString,
    ];
  }

  factory _SubscriptionDurationDto.fromString(String s) {
    return _SubscriptionDurationDto._internal(
      durationString: s,
    );
  }

  // factory _SubscriptionDurationDto.fromEntity(WebSubscriptionDuration subscriptionDuration) {
  //   late final String durationString;
  //
  //   if (subscriptionDuration == WebSubscriptionDuration.month) {
  //     durationString = _kSubscriptionMonthDurationValue;
  //   } else if (subscriptionDuration == WebSubscriptionDuration.year) {
  //     durationString = _kSubscriptionYearDurationValue;
  //   }
  //
  //   return _SubscriptionDurationDto._internal(
  //     durationString: durationString,
  //   );
  // }

  WebSubscriptionDuration toEntity() {
    if (durationString == _kSubscriptionMonthDurationValue) {
      return WebSubscriptionDuration.month;
    }

    if (durationString == _kSubscriptionYearDurationValue) {
      return WebSubscriptionDuration.year;
    }

    throw UnimplementedError();
  }

  @override
  String toString() {
    return durationString;
  }
}
